package com.car.rental.vehicle.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    
    // 用于接收订单服务发送的车辆状态变更消息
    public static final String VEHICLE_STATUS_EXCHANGE = "vehicle.status.exchange";
    public static final String VEHICLE_STATUS_QUEUE = "vehicle.status.queue";
    public static final String VEHICLE_STATUS_ROUTING_KEY = "vehicle.status";
    
    // 声明车辆状态变更队列，用于接收状态变更消息
    @Bean
    public Queue vehicleStatusQueue() {
        return new Queue(VEHICLE_STATUS_QUEUE);
    }
    
    // 声明直连交换机，用于消息路由
    @Bean
    public DirectExchange vehicleStatusExchange() {
        return new DirectExchange(VEHICLE_STATUS_EXCHANGE);
    }
    
    // 将队列和交换机通过路由键绑定，实现消息的定向投递
    @Bean
    public Binding vehicleStatusBinding() {
        return BindingBuilder.bind(vehicleStatusQueue())
                .to(vehicleStatusExchange())
                .with(VEHICLE_STATUS_ROUTING_KEY);
    }
} 